<?php
// 本类由系统自动生成，仅供测试用途
class LoginAction extends Action {
	
	
	public function _initialize()
	{
		$this->assign('loginErr','display:none;');
	}
	
    public function index(){
		
		if ($_POST['txtUserName'])
		{
			$user_name = trim($_POST['txtUserName']);
			$password = trim($_POST['txtUserPwd']);
			$user = M('admin');
			$where['UserName'] = $user_name;
			$where['UserPwd'] = md5($password);
			$where['status'] = 1;
			$result = $user->where($where)->find();
			if ($result)
			{
				$group = M('think_auth_group_access')->where(array('uid' => $result['uid']))->find();
				session('loginGroupId', $group['group_id']);
				session('adminId', $result['uid']); 
				session('admin', $user_name); 
				$this->redirect("Index/index");
			}
			else
			{
				$this->assign('loginErr','display:block;');
			}			
		}
		
		$this->display();
    }
	
	public function logoff()
	{		
		session('adminId', null); 
		session('admin', null);	
		session('loginGroupId', null);	
		$this->redirect("Login/index");
    }	
}